package com.heima.wemedia.controller.v1;

import com.heima.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmMaterialDto;
import com.heima.wemedia.service.MaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by ZYJ on 2021/5/26 20:38
 */
@RestController
@Api(value = "自媒体素材",tags = "自媒体素材")
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private MaterialService materialService;
    @ApiOperation("文件上传")
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(@RequestParam MultipartFile multipartFile){
        return materialService.uploadPicture(multipartFile);
    }

    @PostMapping("/list")
    @ApiOperation("素材列表")
    public ResponseResult findList(@RequestBody WmMaterialDto dto) {
        return materialService.findList(dto);
    }

    @GetMapping("del_picture/{id}")
    @ApiOperation("删除素材")
    public ResponseResult deleteMaterial(@PathVariable Integer id){
        return this.materialService.deleteMaterial(id);
    }

    @GetMapping("/collect/{id}")
    @ApiOperation("收藏素材")
    public ResponseResult collectionMaterial(@PathVariable Integer id){
        return this.materialService.collectionMaterial(id,WemediaConstants.COLLECT_MATERIAL);
    }

    @GetMapping("/cancel_collect/{id}")
    @ApiOperation("取消收藏素材")
    public ResponseResult cancelcollectionMaterial(@PathVariable Integer id){
        return this.materialService.collectionMaterial(id, WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }
}
